package com.oocl.printer.impl;

import java.util.Set;

import com.oocl.pojo.Customer;
import com.oocl.printer.DataPrinter;

/**
 * 格式输出实现
 * 
 * @author GANAB
 * 
 */
public class DataPrinterImpl implements DataPrinter {

	public StringBuilder print(Set<Customer> customers, String format) {
		StringBuilder sb = null;
		if ("xml".equals(format)) {
			sb = new StringBuilder();
			sb.append("<Customers>\r\n");
			for (Customer c : customers) {
				sb.append("  <Customer id=\"" + c.getId() + "\" >\r\n");
				sb.append("    <name>" + c.getName() + "</name>");
				sb.append("    <email>" + c.getEmail() + "</email>");
				sb.append("    <sex>" + c.getSex() + "</sex>");
				sb.append("    <birthday>" + c.getBirthday() + "</birthday>\r\n");
				sb.append("  </Customer>\r\n");
			}
			sb.append("</Customers>\r\n\r\n");
		} else if ("line".equals(format)) {
			sb = new StringBuilder();
			sb.append("ID Name Email Sex birthday\r\n");
			for (Customer c : customers) {
				sb.append(c.getId()+" " + c.getName()+ " " + c.getEmail() +" " +  c.getSex() + " " + c.getBirthday() +"\r\n");
			}
			System.out.println("\r\n");
		} else{
			sb = new StringBuilder("No such as command!\r\n\r\n");
		}
		return sb;

	}

}
